package com.gonsin.gview.model.dynamic.form;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@ApiModel("下拉选择框")
@AllArgsConstructor
@NoArgsConstructor
public class DynamicSwitch extends DynamicFormItem {

    @ApiModelProperty("check_box表示复选框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private final String itemType = "switch";

    @ApiModelProperty("是否必选")
    private boolean required = true;

    @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
    private String keyName;

    @ApiModelProperty("显示的名字")
    private String name;

    @ApiModelProperty("提示语")
    private String placeholder;

    @ApiModelProperty("判断条件显示，支持js语法，例如   showIf=\"type==1\"")
    private String showIf = "1";

    @ApiModelProperty("根据情况禁用")
    private String disableIf = "0";

    @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
    private String onChangeAction;


    /**
     * 2024/7/2 新增
     * 从session中获取权限，如果权限列表不包含该值，则不显示此按钮
     */
    private String[] permission;

    public static DynamicSwitchBuilder builder() {
        return new DynamicSwitchBuilder();
    }


    public static final class DynamicSwitchBuilder {
        @ApiModelProperty("是否必选")
        private boolean required = true;

        @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
        private String keyName;

        @ApiModelProperty("显示的名字")
        private String name;

        @ApiModelProperty("提示语")
        private String placeholder;

        @ApiModelProperty("判断条件显示，支持js语法，例如   showIf=\"type==1\"")
        private String showIf = "1";

        @ApiModelProperty("根据情况禁用")
        private String disableIf = "0";

        @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
        private String onChangeAction;


        /**
         * 2024/7/2 新增
         * 从session中获取权限，如果权限列表不包含该值，则不显示此按钮
         */
        private String[] permission;

        private DynamicSwitchBuilder() {
        }

        public DynamicSwitchBuilder required(boolean required) {
            this.required = required;
            return this;
        }

        public DynamicSwitchBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicSwitchBuilder name(String name) {
            this.name = name;
            return this;
        }

        public DynamicSwitchBuilder placeholder(String placeholder) {
            this.placeholder = placeholder;
            return this;
        }

        public DynamicSwitchBuilder showIf(String showIf) {
            this.showIf = showIf;
            return this;
        }

        public DynamicSwitchBuilder disableIf(String disableIf) {
            this.disableIf = disableIf;
            return this;
        }

        public DynamicSwitchBuilder onChangeAction(String onChangeAction) {
            this.onChangeAction = onChangeAction;
            return this;
        }

        public DynamicSwitch.DynamicSwitchBuilder permission(String[] permission) {
            this.permission = permission;
            return this;
        }

        public DynamicSwitch build() {
            DynamicSwitch dynamicSwitch = new DynamicSwitch();
            dynamicSwitch.setRequired(required);
            dynamicSwitch.setKeyName(keyName);
            dynamicSwitch.setName(name);
            dynamicSwitch.setPlaceholder(placeholder);
            dynamicSwitch.setShowIf(showIf);
            dynamicSwitch.setDisableIf(disableIf);
            dynamicSwitch.setOnChangeAction(onChangeAction);
            dynamicSwitch.setPermission(permission);
            return dynamicSwitch;
        }
    }
}
